package com.hzit.auth.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hzit.auth.mapper.UserMapper;
import com.hzit.auth.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzit.auth.vo.UserVo;
import com.hzit.entity.User;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wf
 * @since 2024-03-05
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

	//1. 根据用户名密码查询用户
	@Override
	public User findByUserVo(UserVo vo) {
		User user = new User();
		BeanUtil.copyProperties(vo,user,true);
		User loginUser = this.getOne(new QueryWrapper<User>().eq("username", vo.getUsername()));
		String pwd = SecureUtil.md5(vo.getPassword());
		if(pwd.equals(loginUser.getPassword())){
			return loginUser;
		}
		return null;
	}
}
